package com.sale.job.service;

import com.pureut.equipment.api.RemoteEquimentService;
import com.sale.system.api.RemoteUserService;
import com.sale.system.api.model.LoginUser;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

/**
 * 设备定时服务
 */
@Slf4j
@Component
public class DeviceService {

    @DubboReference
    RemoteEquimentService remoteEquimentService;

    @DubboReference
    RemoteUserService remoteUserService;


    /**
     * 设备定时任务
     */
    @GlobalTransactional(rollbackFor = Exception.class)
    @XxlJob("ryTask")
    public void ryNoParams() throws Exception {
        LoginUser admin = remoteUserService.getUserInfo("admin");
        XxlJobHelper.log("XXL-JOB, multiServiceHandler result: {}", admin.toString());
        //保养计划修改状态feign
        remoteEquimentService.updateMaintenanceStatusByTime();
        //点检计划修改状态feign
        remoteEquimentService.updateInspectionStatusByTime();
        //巡检计划修改状态feign
        remoteEquimentService.updatePatrolStatusByTime();
        //触发生成工单
        remoteEquimentService.generationWorkOrder();
    }
}
